//
//  submitViewController.m
//  twittsTab2
//
//  Created by Steven Hamilton on 4/7/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "submitViewController.h"
#import "TwitterRequest.h"

@implementation submitViewController

@synthesize weightSlider, cigSlider, glucoseSlider;
@synthesize weightLabel, cigLabel, glucoseLabel;
@synthesize tweetMood, submitAll, moodSwitch,cigSwitch, weightSwitch, glucoseSwitch;


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

-(IBAction) wSliderChange:(UISlider*) sender{
	weight = 200;
	weight = [sender value];
	weightLabel.text = [NSString stringWithFormat:@"%d", weight];
}

-(IBAction)cigSliderChange:(UISlider*) sender{
	cigs = 10;
	cigs = [sender value];
	cigLabel.text = [NSString stringWithFormat:@"%d", cigs];
}

-(IBAction)glucoseSliderChange:(UISlider *) sender{
	glucose  = 110;
	glucose = [sender value];
	glucoseLabel.text = [NSString stringWithFormat:@"%d", glucose];
}


-(IBAction)submitTweet:(id) sender{
	[tweetMood resignFirstResponder];
	
	[self submitMood];
	[self submitWeight];
	[self submitCigs];
	[self submitGlucose];
}

-(void)submitMood{
	NSString *db;
	NSString *dbValue;
	NSString *tempString;
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSString *username;
	NSString *password;
	TwitterRequest *tr = [[TwitterRequest alloc] init];
	if (standardUserDefaults){
		username = [standardUserDefaults objectForKey:@"username"];
		password = [standardUserDefaults objectForKey:@"password"];
	}
	
	if((![tweetMood.text isEqual:@""]) && (moodSwitch.on)){
		
		NSLog(@"user: %@",username);
		tr.username = username;
		tr.password = password;
		
		dbValue = @"m$";
		tempString = tweetMood.text;
		db = [dbValue stringByAppendingString:tempString];
		NSLog(@"mood: %@",db);
		[tr statuses_update:db];
	}
	[tr release];
}

-(void)submitWeight{
	NSString *db;
	NSString *dbValue;
	NSString *tempString;
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSString *username;
	NSString *password;
	TwitterRequest *tr2 = [[TwitterRequest alloc] init];
	
	if (standardUserDefaults){
		username = [standardUserDefaults objectForKey:@"username"];
		password = [standardUserDefaults objectForKey:@"password"];
	}
	
	
	if(weightSwitch.on){
		
		dbValue = @"w$";
		tempString = [NSString stringWithFormat:@"%d", weight];
		db = [dbValue stringByAppendingString:tempString];
		NSLog(@"weight: %@",db);
		tr2.username = username;
		tr2.password = password;
		[tr2 statuses_update:db];
	}
	[tr2 release];
}

-(void)submitCigs{
	NSString *db;
	NSString *dbValue;
	NSString *tempString;
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSString *username;
	NSString *password;
	TwitterRequest *tr = [[TwitterRequest alloc] init];
	
	if (standardUserDefaults){
		username = [standardUserDefaults objectForKey:@"username"];
		password = [standardUserDefaults objectForKey:@"password"];
	}
	
		
	if(cigSwitch.on){
		NSLog(@"user: %@",username);
		tr.username = username;
		tr.password = password;
		
		dbValue = @"c$";
		tempString = [NSString stringWithFormat:@"%d", cigs];
		db = [dbValue stringByAppendingString:tempString];
		NSLog(@"mood: %@",db);
		[tr statuses_update:db];
	}
	
	[tr release];
}

-(void)submitGlucose{
	NSString *db;
	NSString *dbValue;
	NSString *tempString;
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	NSString *username;
	NSString *password;
	TwitterRequest *tr = [[TwitterRequest alloc] init];
	
	if (standardUserDefaults){
		username = [standardUserDefaults objectForKey:@"username"];
		password = [standardUserDefaults objectForKey:@"password"];
	}
	
	
	if(glucoseSwitch.on){
		NSLog(@"user: %@",username);
		tr.username = username;
		tr.password = password;
		
		dbValue = @"g$";
		tempString = [NSString stringWithFormat:@"%d", glucose];
		db = [dbValue stringByAppendingString:tempString];
		NSLog(@"mood: %@",db);
		[tr statuses_update:db];
	}
	
	[tr release];
}

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {  
    if (tweetMood) {  
        if ([tweetMood canResignFirstResponder]) [tweetMood resignFirstResponder];  
    }  
    [super touchesBegan: touches withEvent: event];  
}  

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
